      program exth
      character*200 line
      character*80 fname
      logical use,prt
      
      use=.false.

      call getarg(1,fname)
C      open (10,file=fname(1:lenstr(fname))//'.c',status='old',readonly)
      open (10,file=fname(1:lenstr(fname))//'.c',status='old')

      write (*,'(a/3a/a)') 
     +      '/*','**  File: ',fname(1:lenstr(fname)),'.h','*/'
  100 read (10,'(a)',end=999) line

      if (index(line,'END_EXTH').ne.0) then
         use=.false.
         goto 100
      endif
      if (index(line,'BEGIN_EXTH').ne.0) then
         use=.true.
         prt=.true.
         goto 100
      endif
      if (.not.use) goto 100
      if (prt.and.line(:1).eq.'{') then
c start of function body
         prt=.false.
         goto 100
      endif
      if (.not.prt.and.line(:1).eq.'}') then
c end of function body
         prt=.true.
         goto 100
      endif

      if (prt) then
c skip blank lines
         len=lenstr(line)
         if (len.eq.0) goto 100
c skip comments 
         if (line(1:2).eq.'/*'.or.line(1:2).eq.'*/'
     +       .or.line(1:1).eq.'*') goto 100
c skip remaining code (from block-in-block)
c        do 200 i=1,len
c 200    if (line(i:i).eq.'}') goto 100
c skip preprocessor statements unless include
         do 210 i=1,len
         if (line(i:i).eq.'#') then
            if (line(i:i+7).ne.'#include') goto 100
         endif
  210    continue
c check whether declaration extends over more than one line
         if (index(line,')').eq.0) then
            write (*,'(a,a)') line(1:len)
            goto 100
         endif
         write (*,'(a,a)') line(1:len),';'
      endif
      goto 100

  999 stop
      end
      INTEGER FUNCTION LENSTR(CHARS)
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     FUNCTION LENSTR RETURNS LENGTH OF STRING 'CHARS' EXCLUDING 
C     TRAILING BLANKS
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
      CHARACTER*(*) CHARS
      MVAL = LEN(CHARS)
      DO 10 J = MVAL,1,-1
      IF (CHARS(J:J).NE.' ') GOTO 20
   10 CONTINUE
      J = 0
   20 LENSTR = J
      RETURN
      END
